package Gather.SetExercise;

import java.util.HashSet;

/**
 * ClassName:HashSetText003
 * Package:Gather.SetExercise
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/9-12:32
 * @Version:v1.0
 */
public class HashSetText003 {
    /*需求：创建一个存储学生对象的集合,存储多个学生对象
    * 使用程序实现控制台遍历该集合
    * 要求:学生对象的成员变量值相同,我们就认为是同一个对象*/
    public static void main(String[] args) {
        Student s1 = new Student("zhangsan",23);
        Student s2 = new Student("lisi",24);
        Student s3 = new Student("wangwu",25);
        Student s4 = new Student("zhangsan",23);

        //String Integer  内部已经重写好了HashCode方法

        //创建集合用来添加学生
        HashSet<Student> hs = new HashSet<>();
        System.out.println(hs.add(s3));
        System.out.println(hs.add(s1));
        System.out.println(hs.add(s2));
        System.out.println(hs.add(s4));
        //打印集合
        for (Student h : hs) {
            System.out.println(h);
        }
    }
}
